//
//  SettingDlgViewController.m
//  DJIVideo
//
//  Created by wenpd on 2021/4/8.
//

#import "SettingDlgViewController.h"
#import "Pub_Defines.h"
#import "Constants.h"

@interface SettingDlgViewController ()

@end

@implementation SettingDlgViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self initView];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (void)initView{
    
}


- (IBAction)cancel:(id)sender {
    [self dismissView];
}

- (IBAction)confirm:(id)sender {
    NSString* address = [self trim:self.textAddress.text];
    NSString* pwd = [self trim:self.textPwd.text];
    if(!address.length || [[address substringToIndex:5] isEqual:@"ws://"]){
        NSLog(@"Invild Address.");
    } else if(pwd.length < 6) {
        NSLog(@"Invild Token.");
    } else {
        NSLog(@"input string url:%@, pwd:%@", address, pwd);
        [[NSUserDefaults standardUserDefaults]setObject:address forKey:WS_SERVER_KEY];
        saveUserToken(pwd);
        [self dismissView];
    }
}

-(NSString*)trim:(NSString *)content{
    return [content stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
}

- (void)dismissView{
    [self removeFromParentViewController];
    [self.view removeFromSuperview];
}

+ (CGFloat)obtainWidth{
    return 380.0;
}
+ (CGFloat)obtainHeight{
    return 360.0;
}
@end
